//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pagemodal: true,
    pageIndex: 1,
    makerList: [],
    state:"",
    // 
    uid:"",
    userType:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
      userType: wx.getStorageSync('userType')
    })
    this.GetOperationCenterPartner();
  },

 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetOperationCenterPartner();
  },

 
  //GetOperationCenterPartner
  GetOperationCenterPartner: function() {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var makerList = this.data.makerList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetOperationCenterPartner&PageSize=10&PageIndex=" + pageIndex + "&UID=" + uid),
      success: function(res) {
        console.log("method=GetOperationCenterPartner&PageSize=10&PageIndex=" + pageIndex + "&UID=" + uid);
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        console.log(json);
        for (var i = 0; i < json.length; i++) {
          makerList.push(json[i])
        }
        that.setData({
          makerList: makerList
        })
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
      }
    })

  },
  // 首页
  firstPage: function() {
    this.setData({
      pageIndex: 1
    })
    this.GetOperationCenterPartner();
  },
  // 下一页
  nextPage: function() {
    this.setData({
      pageIndex: pageIndex
    })
    this.GetOperationCenterPartner();

  },
  // agree
  agree: function(e) {
    var that = this;
    var uid = this.data.uid;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=OperaterSuccessPartner&UID=" + e.currentTarget.dataset.makerid + "&OperateId=" + uid),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        console.log(json);
        if (json.ResultFlag == 1) {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          that.GetOperationCenterPartner();
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })
  },
  // refuse
  refuse: function(e) {
    var that = this;
    var uid = this.data.uid;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=OperaterRefusePartner&UID=" + e.currentTarget.dataset.makerid + "&OperateId=" + uid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        console.log(json);
        if (json.ResultFlag == 1) {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          that.GetOperationCenterPartner();
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })

  },
  // 

})